<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8"/>
		<title>工程报异常及解决方法</title>
		<meta name="viewport" content="width=device-width, initial-scale=1"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>	
		<link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen"/>
		<link rel="stylesheet" href="./_assets/css/custom.min.css"/>
	</head>
<body>
	<div class="container">
			
			<div class="row">
				<label class="col-sm-2 col-form-label" for="inputDefault">請依序掃二維碼:</label>
				<input class="form-control" placeholder="AN1811074-X 35M5 4" id="box" type="text">
			</div>
			<div class="card border-primary mb-3" style="max-width: 20rem;">
					<div class="card-header">機台號:BPX0099</div>
					<div class="card-body">
						<h4 class="card-title">異常:</h4>
						<p class="card-text">開始時間:08:23</p>
						<p class="card-text">結束時間:</p>
					</div>
				</div>		
			<div class="row" id="Work_situation">
			</div>
	</div>
	
	<link rel="stylesheet" type="text/css" href="./jexcel-master/dist/css/jquery.jexcel.css" />
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
	<script src="./jexcel-master/dist/js/jquery.jexcel.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	
<script>
	var $btn = $("#keep");
	Plan_data = null; 
	var Shift=null;
	//encodeURIComponent編碼
	//decodeURIComponent後端解碼
	//2018-3-8 21:28:30注釋:為了方便修改,將每個字段頭拆成單行.
	//2018-3-9 15:28:25注釋:已保存備份,以下用新方法快速關聯修改畫面
	//var GongXu = encodeURIComponent($("#WP").val());//工序

	var DT = $("#RiQi").val();//日期
	console.log(DT);
	var times;
	
	column=[
		
		{ type:'text', wordWrap:true },
		{ type:'text', wordWrap:true }
	];		
				
	colHeader=[
		
		'機台號',
		'操機員',
		];
					
	colWidth=[		
		200,
		200,			
		];
	$('#mytable').jexcel({ data:Plan_data,
		// Allow column delete
		allowDeleteColumn:false,
		// Allow row dragging
		rowDrag:false,
		columns:column,
		colHeaders:colHeader,
		colWidths:colWidth
	});
	//默認日期(因為JS沒有日期格式化函數)
	var date = new Date
	hh=date.getHours();  //获取当前小时数(0-23)
	var mm = ""
	var dd = ""
	if ((date.getMonth()+1)>9){
		mm=(date.getMonth()+1)
	}else{
		mm=0+""+(date.getMonth()+1)
	};
	if ((date.getDate())>9){
		dd=(date.getDate())
	}

	if ((date.getDate())<=9){

		dd=0+""+(date.getDate())
	}

	$("#RiQi").val(date.getFullYear()+"-"+mm+"-"+dd);
	
	$("#ZhouBie").val(getWeekOfYear(date))
	
	
	//一天含86,400,000毫秒(24*60*60*1000)
	//公式計算获取本周是一年中的第几周
	function getWeekOfYear(date){
	    var d1 = date;
	    var d2 = new Date(date.getFullYear(), 0, 1);
	    var d = Math.round((d1 - d2) / 86400000);
	    return Math.ceil((d + ((d2.getDay() + 1) - 1)) / 7);
	};
	
	
	
	$("#keep").click(function(){//保存
	Working_Pro= (document.getElementById('WP')).value;//工序
	Shift = $('input[type="radio"][name="classRadios"]:checked').val();//班別
	department= (document.getElementById('department')).value;//部门
		if ((date.getDate())>9){
			dd=(date.getDate())
		}

		if ((date.getDate())<=9){

			dd=0+""+(date.getDate())
		}
		
		Times=date.getFullYear()+"-"+mm+"-"+dd;//時間
		var longdata=new Array();
		longdata = $('#mytable').jexcel('getData', false);
		console.log(longdata);
		
		console.log(datas);
		
		var CXdata10=new Array;
			CXdata10 = $('#mytable').jexcel('getData', false);
			var datas=new Array();
			for(var i = 0, j = 0; i < CXdata10.length; i++){
				
				if (CXdata10[i][0]!=""&&CXdata10[i][1]!=""){//循环判断工单是否=筛选器内容
					datas[j]=new Array(2);
					datas[j][0]=CXdata10[i][0];
					datas[j][1]=CXdata10[i][1];
					j++;
				}
			}
		console.log(datas);
		if(Working_Pro=="-"){
			alert("请选择工序");
		}
		if(department=="-"){
			alert("请选部门");
		}
		if(Shift!="白"&&Shift!="夜"){
			alert("班別不能為空");
		}
		$btn.attr({"disabled":true});//設置為禁用
		$btn.html("更新中,请不要重复点击,如果出不来就用谷歌浏览器!"); 
		if((Shift=="白"||Shift=="夜")&&Working_Pro!="-"&&department!="-"){
			$.ajax({
				type:'POST',
				url: "Operator_Keep.php",//POST傳一個超長字串到後端
				data:"&Working_Pro="+Working_Pro+"&department="+department+"&Shift="+Shift+"&Times="+Times+"&ShuZu="+JSON.stringify(datas),
				dataType : "text",
				success: function(data){
					//$("#msg").val(data).css('color','green');
					$("#msg").val("保存成功");
					$btn.attr({"disabled":false});//設置為啟用 
					$btn.html("保存");
				}
			}); 
		}
		
	});
	
	$("#Yesterday_Work_People").click(function(){//查詢昨日操机员排配
		longdata = $('#mytable').jexcel('getData', false); 
		Shift = $('input[type="radio"][name="classRadios"]:checked').val();//班別
		Working_Pro= (document.getElementById('WP')).value;//工序
		if ((date.getDate()-1)>9){
			dd=(date.getDate()-1)
		}

		if ((date.getDate()-1)<=9){

			dd=0+""+(date.getDate()-1)
		}
		
		Times=date.getFullYear()+"-"+mm+"-"+dd;//時間
		 console.log(Times +"--"+Working_Pro+"--"+Shift);
		
		 $.ajax({
			type:'POST',
			url: "Operator_Yesterday.php",//POST傳一個超長字串到後端
			data:"Working_Pro="+Working_Pro+"&Shift="+Shift+"&Times="+Times,
			dataType : "json",
			success: function(data){

				

				Plan_data = data;
				$('#mytable').jexcel({ data:Plan_data,
					// Allow column delete
					allowDeleteColumn:false,
					// Allow row dragging
					rowDrag:false,
					columns:column,
					colHeaders:colHeader,
					colWidths:colWidth
				});
			}
		}); 
	});
	
	$("#Today_Work_People").click(function(){//查詢今日操机员排配
		longdata = $('#mytable').jexcel('getData', false); 
		Shift = $('input[type="radio"][name="classRadios"]:checked').val();//班別
		Working_Pro= (document.getElementById('WP')).value;//工序
		
		if ((date.getDate())>9){
			dd=(date.getDate())
		}

		if ((date.getDate())<=9){

			dd=0+""+(date.getDate())
		}
		
		

		Times=date.getFullYear()+"-"+mm+"-"+dd;//時間
		 console.log(Times +"--"+Working_Pro+"--"+Shift);
		
		 $.ajax({
			type:'POST',
			url: "Operator_Yesterday.php",//POST傳一個超長字串到後端
			data:"Working_Pro="+Working_Pro+"&Shift="+Shift+"&Times="+Times,
			dataType : "json",
			success: function(data){
				
				Plan_data = data;
				$('#mytable').jexcel({ data:Plan_data,
					// Allow column delete
					allowDeleteColumn:false,
					// Allow row dragging
					rowDrag:false,
					columns:column,
					colHeaders:colHeader,
					colWidths:colWidth
				});
			}
		}); 
	});
</script>
	
</body>
</html>
